﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.ManagementConsole;

namespace GroupMappedDiskSnapInExtension
{
    public class DsObjectNames
    {
        const int OFFSET_SELECTED_OBJECTS_COUNT = 16;        
        const int OFFSET_FIRST_DSOBJECT = 20;
        const int OFFSET_NAME = 8;        

        private SharedData sharedData;

        public DsObjectNames(SharedDataItem sharedDataItem)
        {
            this.Item = sharedDataItem;
        }


        public SharedDataItem Item
        {
            get;
            private set;
        }

        public string DistinguishedName
        {
            get
            {
                string distinguishedName = "";
                MarshalBuffer buffer = new MarshalBuffer(Item.GetData());               
                buffer.ReadInt(OFFSET_SELECTED_OBJECTS_COUNT);                
                int offsetName = buffer.ReadInt((uint) ( OFFSET_FIRST_DSOBJECT + OFFSET_NAME ));
                distinguishedName += buffer.ReadString((uint) offsetName);

                return distinguishedName;
            }
        }
    }
}
